package com.zkingsoft.actions.superaction;

import java.util.Arrays;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zkingsoft.actions.common.BaseController;
import com.zkingsoft.model.Function;
import com.zkingsoft.pojo.AjaxResult;
import com.zkingsoft.services.BtnService;
import com.zkingsoft.services.FunctionService;

/**
 * @description 功能管理action
 * @author 姜友瑶
 * @email 935090232@qq.com
 * @date 2016-06-26
 */
@Controller
@RequestMapping(value = "/super/function")
public class CompanyFunctionController extends BaseController {

	@Resource
	private FunctionService currentService;

	@Resource
	private BtnService btnService;

	@RequestMapping(value = "/all")
	public @ResponseBody AjaxResult all() {
		return findByModel(currentService, null);
	}

	/**
	 * 
	 * @Description: 获取顶层功能
	 * @author:姜友瑶
	 * @param function
	 * @param request
	 * @return 返回类型 AjaxResult
	 * @date 2016年8月31日
	 */
	@RequestMapping(value = "/topFunction")
	public @ResponseBody AjaxResult topFunction(Function function, HttpServletRequest request) {
		function.setGrade(1);
		return new AjaxResult(AjaxResult.STATUS_OK, null, "执行成功", currentService.findByModel(function), 0);

	}

	/**
	 * 根据对象查询
	 * 
	 * @param function
	 * @return
	 */
	@RequestMapping(value = "/findByModel")
	public @ResponseBody AjaxResult findByModel(Function function, HttpServletRequest request) {
		return new AjaxResult(AjaxResult.STATUS_OK, null, "执行成功", currentService.findByModel(function), 0);
	}

	/**
	 * 
	 * @Description: 根据id查询功能
	 * @author:姜友瑶
	 * @param id
	 * @return 返回类型 AjaxResult
	 * @date 2016年8月31日
	 */
	@RequestMapping(value = "/findById")
	public @ResponseBody AjaxResult findById(Long id) {
		Function function = super.findById(currentService, id);
		return new AjaxResult(AjaxResult.STATUS_OK, null, null, Arrays.asList(function), 0);
	}

}